public class RockPaperScissors {

	/**
	 * 
	 * @param p1 move 1
	 * @param p2 move 2
	 * @return win, tie or lost
	 */
	public Result play(RPSEnum p1, RPSEnum p2) {
		// tie
		if (p1.equals(p2))
			return Result.TIE;

		// win
		if (p1.equals(RPSEnum.PAPER) && p2.equals(RPSEnum.ROCK))
			return Result.WIN;
		if (p1.equals(RPSEnum.SCISSORS) && p2.equals(RPSEnum.PAPER))
			return Result.WIN;
		if (p1.equals(RPSEnum.ROCK) && p2.equals(RPSEnum.SCISSORS))
			return Result.WIN;

		// lost
		if (p1.equals(RPSEnum.PAPER) && p2.equals(RPSEnum.SCISSORS))
			return Result.LOST;
		if (p1.equals(RPSEnum.ROCK) && p2.equals(RPSEnum.PAPER))
			return Result.LOST;
		if (p1.equals(RPSEnum.SCISSORS) && p2.equals(RPSEnum.ROCK))
			return Result.LOST;

		return null;
	}

	/**
	 * 
	 * @param p1 player 1
	 * @param p2 player 2
	 * @return win, tie or lost
	 */
	public Result play(Player p1, Player p2) {
		//game session
		RPSEnum choice1, choice2;
		for (int i = 0; i < 10; i++) {
			choice1 = p1.getNextMove();
			choice2 = p2.getNextMove();
			if (play(choice1, choice2).equals(Result.WIN))
				p1.setScore(p1.getScore() + 1);

			else if (play(choice1, choice2).equals(Result.TIE)) {
				p1.setScore(p1.getScore() + 1);
				p2.setScore(p2.getScore() + 1);
			} else if (play(choice1, choice2).equals(Result.LOST))
				p2.setScore(p2.getScore() + 1);

		}
		System.out.println(p1.getScore() + " / " + p2.getScore());
		if (p1.getScore() > p2.getScore())
			return Result.WIN;
		else if (p1.getScore() == p2.getScore())
			return Result.TIE;
		else if (p1.getScore() < p2.getScore())
			return Result.LOST;

		return null;

	}
}
